﻿<phone:PhoneApplicationPage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:UX="clr-namespace:Omnia.UX;assembly=Omnia.UX"
    xmlns:es="clr-namespace:Microsoft.Expression.Shapes;assembly=Microsoft.Expression.Drawing" 
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls" 
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:viewmodels="clr-namespace:Omnia.ViewModels;assembly=Omnia.ViewModels"
    xmlns:Converters="clr-namespace:Omnia.Converters;assembly=Omnia.Converters"
    x:Class="Omnia.Wallet.MainPage"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="False">

    <phone:PhoneApplicationPage.Resources>
    	<Converters:NumberGreaterThanToVisibilityConverter x:Key="NumberGreaterThanToVisibilityConverter"/>
        <Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <Converters:ResourceKeyToPathdataConverter x:Key="ResourceKeyToPathdataConverter"/>
        <Converters:EnumTranslateConverter x:Key="EnumTranslateConverter"/>
        <Converters:NullToResourceStringConverter x:Key="NullToResourceStringConverter"/>
        <Converters:NumberEqualsParameterToVisibilityConverter x:Key="NumberEqualsParameterToVisibilityConverter"/>
    </phone:PhoneApplicationPage.Resources>

    <Grid x:Name="LayoutRoot">
        <Grid.DataContext>
            <viewmodels:HomeViewModel/>
        </Grid.DataContext>
        
        <Grid.Background>
            <ImageBrush Stretch="{Binding GlobalSettings.BackgroundImageStretch}" ImageSource="{Binding BackgroundImageSource, Mode=OneWay}"/>
        </Grid.Background>
        
        <controls:Panorama Title="{StaticResource IDS_APP_TITLE}" >

            <controls:PanoramaItem Header="{StaticResource IDS_HOME_HEADER_DASHBOARD}">
                <Grid >
                    <ScrollViewer>
                        <StackPanel>
                            <UX:UXHomeTitle Margin="12,12,012,0" IconPath="{StaticResource PATH_BID}">
                                <TextBlock>
                                    <Run Text="{StaticResource IDS_LABEL_HOME_TOTAL_AMOUNT}"/>
                                    <Run Text="{Binding TotalAmount, Mode=OneWay, StringFormat=\{0:C\}}"/>
                                </TextBlock>
                            </UX:UXHomeTitle>

                            <Grid Margin="12,12,12,0" Background="{StaticResource PhoneSubtleBrush}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition Width="1"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <StackPanel Margin="0,12">
                                    <TextBlock Text="{Binding TotalIncome, Mode=OneWay, StringFormat=\{0:C\}}" 
                                               Style="{StaticResource PhoneTextTitle3Style}" 
                                               HorizontalAlignment="Center" 
                                               Foreground="{StaticResource PhoneChromeBrush}"/>
                                    <TextBlock Text="{StaticResource IDS_LABEL_HOME_INCOME}" 
                                               Style="{StaticResource PhoneTextNormalStyle}" 
                                               HorizontalAlignment="Center" 
                                               Foreground="{StaticResource PhoneChromeBrush}"/>
                                </StackPanel>
                                <Grid Width="1" Grid.Column="1" Background="{StaticResource PhoneBorderBrush}"/>
                                <StackPanel Grid.Column="2" Margin="0,12">
                                    <TextBlock Text="{Binding TotalExpense, Mode=OneWay, StringFormat=\{0:C\}}" 
                                               Style="{StaticResource PhoneTextTitle3Style}" 
                                               HorizontalAlignment="Center" 
                                               Foreground="{StaticResource PhoneChromeBrush}"/>
                                    <TextBlock Text="{StaticResource IDS_LABEL_HOME_EXPENSE}" 
                                               Style="{StaticResource PhoneTextNormalStyle}" 
                                               HorizontalAlignment="Center" 
                                               Foreground="{StaticResource PhoneChromeBrush}"/>
                                </StackPanel>
                            </Grid>
                            
                            <ProgressBar Value="{Binding IncomePercent, Mode=OneWay}" Height="12" />
                            
                            <Grid Height="1" Margin="12,12,12,12" Background="{StaticResource PhoneBackgroundBrush}"/>

                            <UX:UXHomeItem Margin="12,6" IconPath="{StaticResource PATH_BUDGET}">
                                <StackPanel Margin="0,6">
                                    <TextBlock Style="{StaticResource PhoneTextNormalStyle}" Foreground="{StaticResource PhoneChromeBrush}">
                                        <Run Text="{StaticResource IDS_LABEL_HOME_MONTH_EXPENSE}"/>
                                        <Run Text="{Binding CurrentMonthTransactionExpense.Sum, StringFormat=\{0:C\}}"/>
                                    </TextBlock>
                                    <TextBlock Style="{StaticResource PhoneTextNormalStyle}" Foreground="{StaticResource PhoneChromeBrush}">
                                        <Run Text="{StaticResource IDS_LABEL_HOME_TRANS_COUNT}"/>
                                        <Run Text="{Binding CurrentMonthTransactionExpense.Count}"/>
                                    </TextBlock>
                                    <TextBlock Style="{StaticResource PhoneTextNormalStyle}" Foreground="{StaticResource PhoneChromeBrush}">
                                        <Run Text="{StaticResource IDS_LABEL_HOME_LAST_UPDATE}"/>
                                        <Run Text="{Binding CurrentMonthTransactionExpense.LastUpdate, StringFormat=\{0:MM-dd HH:mm\}}"/>
                                    </TextBlock>
                                </StackPanel>
                            </UX:UXHomeItem>
                            
                            <UX:UXHomeItem Margin="12,6" IconPath="{StaticResource PATH_MONTHLY}">
                                <StackPanel Margin="0,6" VerticalAlignment="Center">
                                    <TextBlock Style="{StaticResource PhoneTextNormalStyle}" Foreground="{StaticResource PhoneChromeBrush}">
                                        <Run Text="{StaticResource IDS_LABEL_HOME_MONTH_BUDGET}"/>
                                        <Run Text="{Binding CurrentBudget.Value, StringFormat=\{0:C\}}"/>
                                    </TextBlock>
                                    <TextBlock Style="{StaticResource PhoneTextNormalStyle}" Foreground="{StaticResource PhoneChromeBrush}">
                                        <Run Text="{StaticResource IDS_LABEL_HOME_MONTH_BUDGET_BALANCE}"/>
                                        <Run Text="{Binding CurrentBudget.Balance}" Foreground="{StaticResource PhoneAccentBrush}"/>
                                    </TextBlock>
                                </StackPanel>
                            </UX:UXHomeItem>
                            
                            <UX:UXHomeItem Margin="12,6" IconPath="{StaticResource PATH_ICON_DEBIT}">
                                <Grid VerticalAlignment="Center" Margin="0,12">
                                    <StackPanel>
                                        <TextBlock Visibility="{Binding RecentRepaymentCount,Converter={StaticResource NumberGreaterThanToVisibilityConverter},ConverterParameter=0}"
                                               Style="{StaticResource PhoneTextNormalStyle}" Foreground="{StaticResource PhoneChromeBrush}">
                                        <Run Text="近期还款："/>
                                        <Run Text="{Binding RecentRepaymentCount}"/>
                                        </TextBlock>
                                        <TextBlock Style="{StaticResource PhoneTextNormalStyle}" 
                                                   Foreground="{StaticResource PhoneChromeBrush}">
                                            <Run Text="{Binding RecentRepaymentCard.IssuingBank}"/>
                                            <LineBreak/>
                                            <Run Text="{Binding RecentRepaymentCard.CardNumber}"/>
                                            <LineBreak/>
                                            <Run Text="{Binding RecentRepaymentCard.NextRepaymentDate,StringFormat=\{0:M\}}"/>
                                        </TextBlock>
                                    </StackPanel>

                                    <TextBlock Visibility="{Binding RecentRepaymentCount,Converter={StaticResource NumberEqualsParameterToVisibilityConverter}, ConverterParameter=0}"
                                               Text="{StaticResource IDS_NOTE_NOREPAYMENT}"
                                               Style="{StaticResource PhoneTextNormalStyle}" 
                                               Foreground="{StaticResource PhoneChromeBrush}"/>
                                </Grid>
                                
                            </UX:UXHomeItem>
                        </StackPanel>
                    </ScrollViewer>
                </Grid>
            </controls:PanoramaItem>

            <controls:PanoramaItem Header="{StaticResource IDS_HOME_HEADER_TRANSACTION}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="12"/>
                        <RowDefinition Height="auto"/>
                    </Grid.RowDefinitions>
                    
                    <ScrollViewer>
                        <StackPanel>
                            <TextBlock Text="{StaticResource IDS_LABEL_TRANS_AMOUNT}" Style="{StaticResource PhoneTextSubtleStyle}" />
                            <TextBox InputScope="Number" 
                                     Text="{Binding ItemToAdd.Amount, Mode=TwoWay, UpdateSourceTrigger=Default}" 
                                     Name="textBoxAmount"/>
                            
                            <!--Kind-->
                            <ListBox Grid.Column="1" VerticalAlignment="Center" Margin="12" 
                                         ItemsSource="{Binding TransactionKinds}" 
                                         SelectedItem="{Binding ItemToAdd.Kind, Mode=TwoWay}" 
                                         SelectionChanged="ListPicker_SelectionChanged">
                                <ListBox.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Horizontal"/>
                                    </ItemsPanelTemplate>
                                </ListBox.ItemsPanel>
                                <ListBox.ItemContainerStyle>
                                    <Style TargetType="ListBoxItem">
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="ListBoxItem">
                                                    <UX:UXRadioButton IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, 
                                                            Path=IsSelected, Mode=TwoWay}">
                                                        <TextBlock Style="{StaticResource PhoneTextNormalStyle}"
                                                                   Text="{Binding Converter={StaticResource EnumTranslateConverter}}"/>
                                                    </UX:UXRadioButton>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </ListBox.ItemContainerStyle>
                            </ListBox>
                            
                            <!--Date & Time-->
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <toolkit:DatePicker Header="{StaticResource IDS_LABEL_TRANS_DATE}" Value="{Binding ItemToAdd.Time, Mode=TwoWay}"/>
                                <toolkit:TimePicker Header="{StaticResource IDS_LABEL_TRANS_TIME}" Value="{Binding ItemToAdd.Time, Mode=TwoWay}" 
                                                    Grid.Column="1"  ValueStringFormat="{}{0:T}"/>
                            </Grid>
                            
                            <!--Category & Payment way-->
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <toolkit:ListPicker ItemsSource="{Binding ShowCategories}" 
                                                    Header="{StaticResource IDS_LABEL_TRANS_CATEGORY}" 
                                                    SelectedItem="{Binding SelectedCategory, Mode=TwoWay}">
                                    <toolkit:ListPicker.ItemTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="auto"/>
                                                    <ColumnDefinition />
                                                </Grid.ColumnDefinitions>
                                                <Path Data="{Binding IconResourceKey, Converter={StaticResource ResourceKeyToPathdataConverter}}" 
                                                      Stretch="Uniform" Fill="#FF818181" 
                                                      Width="20" Height="20" Margin="0,0,0,0" 
                                                      RenderTransformOrigin="0.5,0.5">
                                                    <Path.RenderTransform>
                                                        <TransformGroup>
                                                            <RotateTransform Angle="0" />
                                                            <ScaleTransform ScaleX="1" ScaleY="1" />
                                                        </TransformGroup>
                                                    </Path.RenderTransform>
                                                </Path>
                                                <TextBlock Text="{Binding Name}" Margin="12,0" Grid.Column="1"/>
                                            </Grid>

                                        </DataTemplate>
                                    </toolkit:ListPicker.ItemTemplate>
                                    <toolkit:ListPicker.FullModeItemTemplate>
                                        <DataTemplate>
                                            <Grid Margin="12,6">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="auto"/>
                                                    <ColumnDefinition/>
                                                </Grid.ColumnDefinitions>
                                                <Path Data="{Binding IconResourceKey, Converter={StaticResource ResourceKeyToPathdataConverter}}" 
                                                      Fill="#FF818181" Height="36" Margin="0,0,0,0"
                                                      RenderTransformOrigin="0.5,0.5" Stretch="Uniform" Width="36">
                                                    <Path.RenderTransform>
                                                        <TransformGroup>
                                                            <RotateTransform Angle="0"/>
                                                            <ScaleTransform ScaleY="1" ScaleX="1"/>
                                                        </TransformGroup>
                                                    </Path.RenderTransform>
                                                </Path>
                                                <TextBlock Grid.Column="1" 
                                                           Margin="12,0" 
                                                           Style="{StaticResource PhoneTextTitle2Style}" 
                                                           Text="{Binding Name}"/>
                                            </Grid>
                                        </DataTemplate>
                                    </toolkit:ListPicker.FullModeItemTemplate>
                                </toolkit:ListPicker>
                                <toolkit:ListPicker Grid.Column="1" 
                                                    ItemsSource="{Binding PaymentWays}" 
                                                    Header="{StaticResource IDS_LABEL_TRANS_PAYMENTWAY}" 
                                                    SelectedItem="{Binding ItemToAdd.Paymentway, Mode=TwoWay}">
                                    <toolkit:ListPicker.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Converter={StaticResource EnumTranslateConverter}}"/>
                                        </DataTemplate>
                                    </toolkit:ListPicker.ItemTemplate>
                                </toolkit:ListPicker>
                            </Grid>
                            
                            <!--Transaction Place-->
                            <TextBlock Text="{StaticResource IDS_LABEL_TRANS_PLACE}" Style="{StaticResource PhoneTextSubtleStyle}"/>
                            <toolkit:AutoCompleteBox ItemsSource="{Binding StorePlaceCollection, Mode=OneWay}" 
                                                     ValueMemberPath="Place" 
                                                     Text="{Binding ItemToAdd.Place, Mode=TwoWay}" 
                                                     FilterMode="Contains">
                                <toolkit:AutoCompleteBox.ItemTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Place}" />
                                    </DataTemplate>
                                </toolkit:AutoCompleteBox.ItemTemplate>
                            </toolkit:AutoCompleteBox>
                            
                            <!--Remark-->
                            <TextBlock Text="{StaticResource IDS_LABEL_TRANS_REMARK}" 
                                       Style="{StaticResource PhoneTextSubtleStyle}"/>
                            <TextBox TextWrapping="Wrap" Text="{Binding ItemToAdd.Remark, Mode=TwoWay}"/>
                            
                            <!--Link To Case-->
                            <CheckBox Content="{StaticResource IDS_LABEL_TRANS_LINKTOCASE}" 
                                      IsChecked="{Binding LinkToCase, Mode=TwoWay}" 
                                      HorizontalAlignment="Left"/>
                            <toolkit:AutoCompleteBox IsEnabled="{Binding LinkToCase}" 
                                                     ItemsSource="{Binding CasesCollection, Mode=OneWay}" 
                                                     ValueMemberPath="Title" 
                                                     SelectedItem="{Binding SelectedCase, Mode=TwoWay}" 
                                                     Visibility="{Binding LinkToCase, Converter={StaticResource BooleanToVisibilityConverter}}"
                                                     FilterMode="Contains" >
                                <toolkit:AutoCompleteBox.ItemTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Title}"/>
                                    </DataTemplate>
                                </toolkit:AutoCompleteBox.ItemTemplate>
                            </toolkit:AutoCompleteBox>
                        </StackPanel>
                    </ScrollViewer>

                    <!--Submit & Cancle Button-->
                    <StackPanel Grid.Row="2" 
                                Margin="0,0,0,12"
                                Orientation="Horizontal" 
                                HorizontalAlignment="Right" 
                                Visibility="{Binding Text, ElementName=textBoxAmount, ConverterParameter=0, Converter={StaticResource NumberGreaterThanToVisibilityConverter}}">
                        <UX:UXPathButton Margin="12,0" 
                                         IconPath="{StaticResource PATH_ICON_SUBMIT}" 
                                         Command="{Binding AddTransactionCommand, Mode=OneWay}" Padding="10"/>
                        
                        <UX:UXPathButton Margin="12,0" 
                                         IconPath="{StaticResource PATH_ICON_CLOSE}" 
                                         Padding="13"
                                         Command="{Binding CancleAddTransactionCommand, Mode=OneWay}"/>
                    </StackPanel>
                </Grid>
            </controls:PanoramaItem>

            <controls:PanoramaItem Header="{StaticResource IDS_HOME_HEADER_MENU}">
                <ScrollViewer>
                    <StackPanel>
                        <UX:UXLinkMenu Content="{StaticResource IDS_HOME_MENU_TRAN_DETAIL}" Uri="/Views/TransactionsView.xaml"/>
                        <UX:UXLinkMenu Content="{StaticResource IDS_HOME_MENU_TRAN_CATEGORY}" Uri="/Views/CategoriesView.xaml"/>
                        <UX:UXLinkMenu Content="{StaticResource IDS_HOME_MENU_MONTHLY_BUDGET}" Uri="/Views/BUdgetsView.xaml"/>
                        <UX:UXLinkMenu Content="{StaticResource IDS_HOME_MENU_CASE}" Uri="/Views/CasesView.xaml"/>
                        <UX:UXLinkMenu Content="{StaticResource IDS_HOME_MENU_CARDS}" Uri="/Views/CardsView.xaml"/>
                        <UX:UXLinkMenu Content="{StaticResource IDS_HOME_MENU_STATISTICS}" Uri="/Views/StatisticsView.xaml"/>
                        <UX:UXLinkMenu Content="{StaticResource IDS_HOME_MENU_FAVIPLACE}" Uri="/Views/FavoritePlaceView.xaml"/>
                        <UX:UXLinkMenu Content="{StaticResource IDS_HOME_MENU_PREFERENCE}" Uri="/Views/PreferenceView.xaml"/>
                        <UX:UXLinkMenu Content="{StaticResource IDS_HOME_MENU_ABOUTANDHELP}" Uri="/Views/AboutAndHelpView.xaml"/>
                    </StackPanel>
                </ScrollViewer>
            </controls:PanoramaItem>
        </controls:Panorama>
    </Grid>
</phone:PhoneApplicationPage>